<!DOCTYPE html>
<html manifest="cache.appcache">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
		<title>快知</title>
		<meta name="keywords" content="快知" />
		<meta name="description" content="快知,聚合主流热门的搜索引擎的搜索结果,根据关键字同步调用各大搜索引擎,完成内容的聚合,极大提高搜索效率,快速定位目标信息" />
		<script src="./js/jquery-1.11.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="./js/fSelect.js" type="text/javascript" charset="utf-8"></script>
		<script src="./js/jquery.mCustomScrollbar.concat.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/font-awesome/4.6.0/css/font-awesome.min.css" />
		<link rel="stylesheet" type="text/css" href="./css/fSelect.css" />
		<link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
		<link rel="stylesheet" type="text/css" href="./css/jquery.mCustomScrollbar.css" />
		<link rel="stylesheet" type="text/css" href="./css/index.css" />
        <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
	</head>
	<body>
		<header class="">
			<a href="" class="logo">
				<h2>
					快知
				</h2>
			</a>
			<div class="search-box">
				<div id="search-input-box" class="search-input-box">
					<input id="keywords" name="q" type="search" autocomplete="on" value="" placeholder="输入关键字搜索" />
					<button onclick="search()"></button>
				</div>
				<div id="search-keywords" class="search-keywords">
					<ul></ul>
				</div>
			</div>
			<div class="menu-btn">
				<div class="line line__1"></div>
				<div class="line line__2"></div>
				<div class="line line__3"></div>
			</div>

		</header>


		<div id="content" class="clearfix">
			<div class="navigation" tabindex="0" outline=0" hidefocus="true">

				<div id="vtab" class="vtab">
					<ul id="cur_subtype" style="">
					</ul>

					<a class="addbtn fa-plus"></a>
					<div class="funcmenu none">
						<ul>
							<li name="addsite"><a href="javascript:void(0);">添加站点源</a></li>
							<li name="addmultiple"><a href="javascript:void(0);">添加多窗口搜索</a></li>
							<li name="typemgr"><a href="javascript:void(0);">分组管理</a></li>
							<li><a href="./help.html">使用说明</a></li>
						</ul>
					</div>


				</div>

				<div class="sitelist">
					<ul id="faveriters">
					</ul>
					<ul id="websites">
					</ul>
				</div>
			</div>
			<div class="main-content">
				<div class="nothing">
				</div>
				<div class="content template1">
					<iframe id="engine" src="./book.html" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="true"
					 style="background-color:#fff;"></iframe>
				</div>
				<div class="content template2 none">
					<iframe id="engine1" src="" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="true" style="background-color:#fff"></iframe>
					<iframe id="engine2" src="" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="true" style="background-color:#fff"></iframe>
				</div>
				<div class="content template3 none">
					<iframe id="engine1" src="" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="true" style="background-color:#fff"></iframe>
					<iframe id="engine2" src="" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="true" style="background-color:#fff"></iframe>
					<iframe id="engine3" src="" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="true" style="background-color:#fff"></iframe>
				</div>
				<div class="content template4 none">
					<iframe id="engine1" src="" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="true" style="background-color:#fff"></iframe>
					<iframe id="engine2" src="" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="true" style="background-color:#fff"></iframe>
					<iframe id="engine3" src="" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="true" style="background-color:#fff"></iframe>
					<iframe id="engine4" src="" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="true" style="background-color:#fff"></iframe>
				</div>
			</div>
		</div>


		<div class="modal">
			<div id="addsite-modal" class="modal-box">
				<a href="javascript:void(0);" class="modal-close"><b>关闭</b></a>
				<div class="modal-title">
					<h2>添加站点源</h2>
				</div>
				<div class="modal-content">
					<div class="modal-content-box">
						<form>
							<a>站点显示名称(必填)</a><span id="site-name-req" class="none">*</span>
							<div class="modal-input-item">
								<input name="site-name" type="text" placeholder="例如：谷歌" autocomplete="off" value="test" />
							</div>
							<a>站点描述(可选)</a>
							<div class="modal-input-item">
								<input name="site-memo" type="text" placeholder="例如：全球最大的搜索引擎" autocomplete="off" />
							</div>
							<a>站点地址,无关键字搜索时进入的地址(必填)</a><span id="site-url-req" class="none">*</span>
							<div class="modal-input-item">
								<input name="site-url" type="text" placeholder="例如：https://google.com" autocomplete="off" value="例如：https://google.com" />
							</div>
							<a>关键字搜索地址,地址中请用{keywords}代表搜索关键字(必填)</a><span id="site-query-req" class="none">*</span>
							<div class="modal-input-item">
								<input name="site-query" type="text" placeholder="https://www.google.com/search?q={keywords}" autocomplete="off"
								 value="https://www.google.com/search?q={keywords}" />
							</div>
							<a>网站图标地址(必填)</a><span id="site-ico-req" class="none">*</span>
							<div class="modal-input-item">
								<input name="site-ico" type="text" placeholder="https://google.com/favicon.ico" autocomplete="off" value="https://google.com/favicon.ico" />
							</div>
							<a>所在分组</a>
							<div class="select">
								<ul>
								</ul>
							</div>
						</form>
						<div class="modal-footer">
							<button class="modal-button">保存</button>
							<button class="modal-button graybtn">删除</button>

						</div>
					</div>
				</div>
			</div>

			<div id="addmultiple-modal" class="modal-box">
				<a href="javascript:void(0);" class="modal-close"><b>关闭</b></a>
				<div class="modal-title">
					<h2>添加多窗口搜索</h2>
				</div>
				<div class="modal-content">
					<div class="modal-content-box">
						<form>
							<a>显示名称(必填)</a><span id="multiple-name-req" class="none">*</span>
							<div class="modal-input-item">
								<input name="multiple-name" type="text" placeholder="例如：谷歌，百度" autocomplete="off" />
							</div>
							<a>描述(可选)</a>
							<div class="modal-input-item">
								<input name="multiple-memo" type="text" placeholder="例如：谷歌，百度同时搜索" autocomplete="off" />
							</div>
							<a>同时打开的站点，多选，2-4个(必填)</a><span id="multiple-sites-req" class="none">*</span>
							<div class="container">
								<select class="typeselecter" multiple="multiple">
								</select>
							</div>

							<a>所在分组</a>
							<div class="select">
								<ul>
								</ul>
							</div>
						</form>
						<div class="modal-footer">
							<button class="modal-button">保存</button>
							<button class="modal-button graybtn">删除</button>

						</div>
					</div>
				</div>
			</div>

			<div id="typemgr-modal" class="modal-box">
				<a href="javascript:void(0);" class="modal-close"><b>关闭</b></a>
				<div class="modal-title">
					<h2>分组管理</h2>
				</div>
				<div class="modal-content">
					<div class="modal-content-box">

						<div class="select">
							<ul>
							</ul>
						</div>


						<div class="right">

							<div class="modal-input-item">
								<input name="typename" type="text" placeholder="" autocomplete="off" />
							</div>
							<span id="typemgr-req" class=""></span>
							<button class="modal-button">保存</button>
							<button class="modal-button graybtn">删除</button>
						</div>
						</form>
						<div class="modal-footer">


						</div>
					</div>
				</div>
			</div>

		</div>


		<script type='text/javascript'>
			jQuery.fn.isChildAndSelfOf = function(b) {
				return (this.closest(b).length > 0);
			};

			function getQueryVariable(variable) {
				var query = window.location.search.substring(1);
				var vars = query.split("&");
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split("=");
					if (pair[0] == variable) {
						return decodeURI(pair[1]);
					}
				}
				return "";
			}
			/**
			 * cookie中存值
			 * */
			function setCookie(name, value) {

				var days = 365; //定义一天
				var exp = new Date();
				exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
				// 写入Cookie, toGMTString将时间转换成字符串
				document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();

			};

			/**
			 * cookie中取值
			 * */
			function getCookie(name) {
				var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //匹配字段
				if (arr = document.cookie.match(reg)) {
					return unescape(arr[2]);
				} else {
					return "";
				}
			};

			function browserRedirect() {
				var sUserAgent = navigator.userAgent.toLowerCase();
				if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(sUserAgent)) {
					//跳转移动端页面
					$(".navigation").addClass('hide');
					$(".nothing").css("display", "none");
					$("#content").addClass('bottomside');
					$("header").addClass('bottomside');
				} else {
					//跳转pc端页面
					$("#content").addClass('leftside');
				}
			}
			browserRedirect();



			var types = [{
				"name": "资源",
				"user": false
			}, {
				"name": "搜索",
				"user": false
			} /*,{"name":"多窗口","user":false}*/ ];

			var sites = [
				[
					["茶杯狐", "茶杯狐搜索", "https://www.cupfox.app", "https://www.cupfox.app/search?key={keywords}","https://i.loli.net/2018/08/04/5b65b28a65aae.png", false, false],
                    // ["追影猫", "追影猫搜索", "https://zhuiyingmao.com", "https://zhuiyingmao.com/vodsearch/-------------.html?wd={keywords}","https://zhuiyingmao.com/favicon.ico", false, false],
					// ["电影狗", "电影狗搜索", "https://www.dianyinggou.com", "https://www.dianyinggou.com/so/{keywords}","https://www.dianyinggou.com/favicon.ico", false, false],
				],
				[
					["必应", "必应搜索引擎", "https://cn.bing.com", "https://cn.bing.com/search?q={keywords}", "https://cn.bing.com/favicon.ico", false,false],
					// ["搜狗", "搜狗搜索引擎", "https://www.sogou.com", "https://www.sogou.com/web?query={keywords}","https://www.sogou.com/images/logo/new/favicon.ico", false, false],
				],
				/*
				[
					["二窗","百度一下","multiple","百度;搜狗","template2",false,false],
					["三窗","百度一下","multiple","百度;搜狗;s360","template3",false,false],
					["四窗","百度一下","multiple","百度;搜狗;s360;必应","template4",false,false],
				]
				*/
			];




			/*
			function tojson(){
				var arr = [[]];
					for(index in types){
						var items = sites[index];
						arr.push([]);
						for(i in items){
							var json = {};
							json.name = items[i][0];
							json.memo = items[i][1];
							json.url = items[i][2];
							json.query = items[i][3];
							json.ico = items[i][4];
							json.favorite = items[i][5];
							json.user = items[i][6];
							arr[index].push(JSON.stringify(json));
						}
					}
					var sd = JSON.stringify( arr );
				}
			tojson();

			var sd = JSON.stringify( sites );
			jsarr=JSON.parse( sd );
			sd = JSON.stringify( jsarr );
			*/
			function hasSametypename(name) {
				for (i in types) {
					if (types[i].name === name) {
						return true;
					}
				}

				return false;
			}

			function gettypeindex(name) {
				for (i in types) {
					if (types[i].name === name) {
						return i;
					}
				}
				return -1;
			}

			function getwebsiteindex(name) {
				for (index in types) {
					var items = sites[index];
					for (i in items) {
						if (items[i][0] === name) {
							return i;
						}
					}
				}
				return -1;
			}

			function getwebsiteindex(index, name) {
				var items = sites[index];
				for (i in items) {
					if (items[i][0] === name) {
						return i;
					}
				}
				return -1;
			}

			function bulidtype() {

				var $sub_ui = $('#cur_subtype');
				$sub_ui.empty();
				//sort
				var sortstr = getCookie("sort_type");
				var items = sortstr.split(';');

				for (i in types) {
					var has = false;
					for (j in items) {
						if (types[i].name === items[j]) {
							has = true;
							break;
						}
					}
					if (!has) {
						items.push(types[i].name);
					}
				}

				for (var num in items) {
					i = gettypeindex(items[num]);
					if (i < 0) continue;
					var $newElement = $('<li draggable="true"><a href="javascript:;" >' + types[i].name + '</a></li>');
					$newElement.attr("typeindex", i);

					$sub_ui.append($newElement);

				}

				var $items = $('#vtab>ul>li');
				$items.eq(0).addClass('selected');
				$items.click(function() {
					$items.removeClass('selected');
					$(this).addClass('selected');

					selecttabtype($(this).attr("typeindex"));
				});
			}

			function bulidfavorites() {
				$faveriters = $('#faveriters');
				$faveriters.empty();
				var favorite = getCookie("favorite");
				if (favorite == "") return;
				var items = favorite.split(';');
				for (i in items) {
					var name = items[i];
					if (name == "")
						continue;

					var has = false;
					var typeindex = -1;
					var subindex = -1;
					for (var t in types) {
						var site = sites[t];
						for (var index in site) {
							if (site[index][0] == name) {
								site[index][5] = true
								has = true;
								typeindex = t;
								subindex = index;
								break;
							}
						}
						if (has) break;
					}
					if (!has) continue;

					var $newElement = null;
					if (sites[typeindex][subindex][2] == "multiple")
						$newElement = $('<li draggable="true"><img src="./images/4.jpg"><span>' + sites[typeindex][subindex][0] +
							'</span><a class="hover-content favorite"><img src="./images/on.svg"></a><i class="hover-content fa fa-cog fa-lg modify"></i></li>'
						);
					else if (sites[typeindex][subindex][6] == true)
						$newElement = $('<li draggable="true"><img src="' + sites[typeindex][subindex][4] + '"><span>' + sites[typeindex]
							[subindex][0] +
							'</span><a class="hover-content favorite"><img src="./images/on.svg"></a><i class="hover-content fa fa-cog fa-lg modify"></i></li>'
						);
					else
						$newElement = $('<li draggable="true"><img src="' + sites[typeindex][subindex][4] + '"><span>' + sites[typeindex]
							[subindex][0] + '</span><a class="hover-content favorite"><img src="./images/on.svg"></a></li>');
					$newElement.attr("typeindex", typeindex);
					$newElement.attr("index", subindex);
					$newElement.click(function(event) {

						var typeindex = $(this).attr("typeindex");
						webindex = $(this).attr("index");
						var site = sites[typeindex][webindex];
						if ($(event.target).isChildAndSelfOf(".favorite")) {
							site[5] = false;
							var favorite = getCookie("favorite");
							var items = favorite.split(';');
							favorite = "";
							for (i in items) {
								var name = items[i];
								if (name == "")
									continue;
								if (name == site[0])
									continue;

								favorite += ";" + name;
							}
							if (favorite.length > 0)
								favorite = favorite.substr(1);
							setCookie("favorite", favorite);
							//重新加载
							bulidfavorites();
							selecttabtype($('#cur_subtype>li.selected').attr("typeindex"));
						} else if ($(event.target).isChildAndSelfOf(".modify")) {
							$(".modal").attr("modify", true);
							$(".modal").attr("typeindex", typeindex);
							$(".modal").attr("siteindex", webindex);

							if (site[2] == "multiple") {
								$(".funcmenu li[name='addmultiple']").click();
							} else {
								$(".funcmenu li[name='addsite']").click();
							}
						} else {
							$('#websites>li').removeClass("active");
							var $items = $('#faveriters>li');
							$items.removeClass("active");
							$items.eq($(this).index()).addClass('active');

							selectwebsite(typeindex, webindex);
						}
					});

					$faveriters.append($newElement);


				}
				if (items.length > 0)
					$faveriters.append('<li class="split" ></li>');

			}

			function selecttabtype(index) {
				var $websites = $('#websites');
				$websites.empty();
				var items = sites[index];
				//sort
				var sortstr = getCookie("sort_websits_" + index);
				var sortitems = sortstr.split(';');
				var sort = [];

				for (i in items) {
					var has = false;
					for (j in sortitems) {
						if (items[i][0] === sortitems[j]) {
							has = true;
							break;
						}
					}
					if (!has) {
						sortitems.push(items[i][0]);
					}
				}


				for (var num in sortitems) {
					var i = getwebsiteindex(index, sortitems[num]);
					if (i < 0) continue;

					if (items[i][5] == true)
						continue;

					var $newElement = null;
					if (items[i][2] == "multiple")
						$newElement = $('<li draggable="true"><img src="./images/4.jpg"><span>' + items[i][0] +
							'</span><a class="hover-content favorite"><img src="./images/off.svg"></a><i class="hover-content fa fa-cog fa-lg modify"></i></li>'
						);
					else if (items[i][6] == true)
						$newElement = $('<li draggable="true"><img src="' + items[i][4] + '"><span>' + items[i][0] +
							'</span><a class="hover-content favorite"><img src="./images/off.svg"></a><i class="hover-content fa fa-cog fa-lg modify"></i></li>'
						);
					else
						$newElement = $('<li draggable="true"><img src="' + items[i][4] + '"><span>' + items[i][0] +
							'</span><a class="hover-content favorite"><img src="./images/off.svg"></a></li>');
					$newElement.attr("typeindex", index);
					$newElement.attr("index", i);
					$newElement.click(function(event) {
						var typeindex = $(this).attr("typeindex");
						webindex = $(this).attr("index");
						var site = sites[typeindex][webindex];
						if ($(event.target).isChildAndSelfOf(".favorite")) {
							var favorite = getCookie("favorite");
							favorite += ";" + site[0];
							setCookie("favorite", favorite);
							//重新加载
							bulidfavorites();
							selecttabtype(typeindex);
						} else if ($(event.target).isChildAndSelfOf(".modify")) {
							$(".modal").attr("modify", true);
							$(".modal").attr("typeindex", typeindex);
							$(".modal").attr("siteindex", webindex);

							if (site[2] == "multiple") {
								$(".funcmenu li[name='addmultiple']").click();
							} else {
								$(".funcmenu li[name='addsite']").click();
							}
						} else {
							$('#faveriters>li').removeClass("active");
							var $items = $('#websites>li');
							$items.removeClass("active");
							$items.eq($(this).index()).addClass('active');
							selectwebsite(typeindex, webindex);
						}
					});

					$websites.append($newElement);
				}

			}

			function getnameurl(name, keyword) {
				for (var i in types) {
					for (var j in sites) {
						if (sites[i][j][0] === name)
							return keyword ? sites[i][j][3] : sites[i][j][2];
					}
				}
				return "";
			}

			function realsearch(index, webindex, kws) {
				var site = sites[index][webindex];
				if (site[2] === "multiple") {
					var items = site[3].split(';');
					var template = ".template" + items.length;
					for (i in items) {
						var url = getnameurl(items[i], kws !== "");
						var id = parseInt(i) + 1;
						var engine = template + " #engine" + id;
						url = url.replace(/{keywords}/g, kws);
						$(engine).attr("src", url);
					}

					$(".template1").addClass('none');
					$(".template2").addClass('none');
					$(".template3").addClass('none');
					$(".template4").addClass('none');
					$(template).removeClass('none');

				} else {
					if (kws == "")
						url = site[2];
					else
						url = site[3];
					url = url.replace(/{keywords}/g, kws);
					$("#engine").attr("src", url);

					$(".template1").removeClass('none');
					$(".template2").addClass('none');
					$(".template3").addClass('none');
					$(".template4").addClass('none');
				}
			}

			function selectwebsite(index, webindex) {

				var kws = $("#keywords").val();

				realsearch(index, webindex, kws);
				if ($("header").hasClass('bottomside')) {
					$(".navigation").addClass('hide');
					$(".nothing").css("display", "none");
				}

			}

			function search() {
				var kws = $("#keywords").val();
				if (kws == '')
					return;

				var $selitem = $('#faveriters>li.active');
				if (!$selitem[0])
					$selitem = $('#websites>li.active');
				if ($selitem[0]) {
					webindex = $selitem.attr("index");
					index = $selitem.attr("typeindex");
				} else
					webindex = -1;
				if (webindex < 0) {
					var $items = $('#faveriters>li');
					if (!$items[0]) {
						$items = $('#websites>li');
					}
					index = $items.eq(0).attr("typeindex");
					webindex = $items.eq(0).attr("index");
					$items.eq(0).addClass('active');
				}
				realsearch(index, webindex, kws);
			}

			//读自定义数据
			var str = getCookie("usertypes");
			if (str !== "") {
				var usertypes = JSON.parse(str);
				let temp = types.concat(usertypes);
				types = temp;
				for (i in usertypes) {
					sites.push([]); //放一个空数组，预防该组下没站点数据而导致出差
				}
			}

			for (index in types) {
				str = getCookie("usersites_" + index);
				if (str === "")
					continue;
				tempsites = JSON.parse(str);
				if (tempsites.length > 0) {
					let temp = sites[index].concat(tempsites);
					sites[index] = temp;
				}
			}

			bulidtype();
			bulidfavorites();
			var first = $('#cur_subtype li').attr("typeindex");
			selecttabtype(first);

			var kw = getQueryVariable("kw");
			if (kw != "") {
				$("#keywords").attr("value", kw);
				search();
			}


			$(".menu-btn").click(function() {

				if ($(".navigation").hasClass('hide')) {
					$(".navigation").removeClass('hide');
					if ($("#content").hasClass('bottomside'))
						$(".nothing").css("display", "block");
					else
						$(".main-content").css("width", "calc(100% - 250px)");
				} else {
					$(".navigation").addClass('hide');
					if ($("#content").hasClass('bottomside'))
						$(".nothing").css("display", "none");
					else
						$(".main-content").css("width", "100%");
				}

			});



			$('body').bind('click', function(event) {
				if (!$("#content").hasClass('bottomside'))
					return;
				if ($(event.target).isChildAndSelfOf(".navigation")) return;
				if ($(event.target).isChildAndSelfOf(".menu-btn")) return;

				$(".navigation").addClass('hide');
				$(".nothing").css("display", "none");

			});

			(function($) {
				$(window).load(function() {
					$(".sitelist").mCustomScrollbar({
						mouseWheel: true,
						scrollButtons: {
							enable: false
						},
						advanced: {
							updateOnContentResize: true
						}
					});
				});
			})(jQuery);

			$(document).ready(function() {


			});
		</script>

		<script>
			$(".addbtn").hover(function() {
				$(".funcmenu").removeClass('none');
			}, function() {
				$(".funcmenu").addClass('none');
			});
			$(".funcmenu").hover(function() {
				$(".funcmenu").removeClass('none');
			}, function() {
				$(".funcmenu").addClass('none');
			});


			$(".funcmenu li").click(function() {
				$(".modal").addClass('active');
				$(".modal").css("display", "block");
				var name = $(this).attr("name");
				if (name == "addsite" || name == "addmultiple") {
					var ulname = "";
					if (name == "addsite")
						ulname = "#addsite-modal";
					else
						ulname = "#addmultiple-modal";

					$ul = $(ulname + " .select ul");
					$ul.empty();
					for (var i in types) {
						var $newElement = $('<li><a href="javascript:;" >' + types[i].name + '</a></li>');
						$newElement.attr("typeindex", i);
						$ul.append($newElement);

					}
					$(ulname + " .select li").eq(0).addClass("selected");
					$(ulname + " .select li").click(function() {
						$(ulname + " .select li").removeClass('selected');
						$(this).addClass("selected");
					});

				}
				if (name == "addsite") {
					$("#addsite-modal").addClass('active');
					$("#addsite-modal").css("display", "block");

					$("#addsite-modal input[name='site-name']").val("");
					$("#addsite-modal input[name='site-memo']").val("");
					$("#addsite-modal input[name='site-url']").val("");
					$("#addsite-modal input[name='site-query']").val("");
					$("#addsite-modal input[name='site-ico']").val("");
					$("#addsite-modal .graybtn").addClass('none');

					if ($(".modal").attr("modify") == "true") {
						$("#addsite-modal .graybtn").removeClass('none');
						$("#addsite-modal .modal-title h2").html("编辑站点源");
						var typeindex = $(".modal").attr("typeindex");
						var site = sites[parseInt(typeindex)][parseInt($(".modal").attr("siteindex"))];
						$("#addsite-modal input[name='site-name']").val(site[0]);
						$("#addsite-modal input[name='site-memo']").val(site[1]);
						$("#addsite-modal input[name='site-url']").val(site[2]);
						$("#addsite-modal input[name='site-query']").val(site[3]);
						$("#addsite-modal input[name='site-ico']").val(site[4]);

						$("#addsite-modal .select ul li").removeClass("selected");
						$("#addsite-modal .select ul li:eq(" + typeindex + ")").addClass("selected");
					}
				} else if (name === "addmultiple") {
					var html = '';
					for (index in types) {
						var items = sites[index];
						html += '<optgroup label="' + types[index].name + '">';
						for (i in items) {
							html += '<option value="' + items[i][0] + '">' + items[i][0] + '</option>';
						}
						html += '</optgroup>';
					}
					$('.typeselecter').html(html);
					$('.typeselecter').fSelect();
					$('.fs-optgroup .fs-option').removeClass("selected");
					$("#addmultiple-modal").addClass('active');
					$("#addmultiple-modal .graybtn").addClass('none');
					$("#addmultiple-modal").css("display", "block");


					$("#addmultiple-modal input[name='multiple-name']").val("");
					$("#addmultiple-modal input[name='multiple-memo']").val("");
					$("#addmultiple-modal .fs-label").html("请选择站点");

					if ($(".modal").attr("modify") == "true") {
						$("#addmultiple-modal .graybtn").removeClass('none');
						$("#addmultiple-modal .modal-title h2").html("编辑多窗口搜索");
						var typeindex = $(".modal").attr("typeindex");
						var site = sites[parseInt(typeindex)][parseInt($(".modal").attr("siteindex"))];
						$("#addmultiple-modal input[name='multiple-name']").val(site[0]);
						$("#addmultiple-modal input[name='multiple-memo']").val(site[1]);
						$("#addmultiple-modal .fs-label").html(site[3]);
						$("#addmultiple-modal .select ul li").removeClass("selected");
						$("#addmultiple-modal .select ul li:eq(" + typeindex + ")").addClass("selected");
						var items = site[3].split(';');
						for (var i in items) {
							$('.fs-optgroup .fs-option[data-value="' + items[i] + '"]').addClass("selected");
						}
					}
				} else if (name === "typemgr") {

					$ul = $("#typemgr-modal .select ul");
					$ul.empty();
					for (var i in types) {
						if (!types[i].user)
							continue;
						var $newElement = $('<li><a href="javascript:;" >' + types[i].name + '</a></li>');
						$ul.append($newElement);

					}
					$("#typemgr-modal input[name='typename']").val("");
					$ul.append('<li class="fa-plus" style="cursor:pointer;" ></li>');

					$("#typemgr-modal .select li").click(function() {
						if (!$(this).hasClass("fa-plus")) {
							$("#typemgr-modal .select li").removeClass('selected');
							$(this).addClass("selected");

							$("#typemgr-modal input[name='typename']").val($(this).children('a').text());
						}
					});

					$("#typemgr-modal .select .fa-plus").click(function() {
						var name = "分组";
						var newname = name;
						var i = 0;
						while (gettypeindex(newname) >= 0) {
							i++;
							newname = "分组" + i;
						}
						types.push({
							"name": newname,
							"user": true
						});
						sites.push([]);
						var index = gettypeindex(newname);
						var $newElement = $('<li><a href="javascript:;" >' + newname + '</a></li>');
						$ul = $("#typemgr-modal .select ul li");
						$newElement.insertBefore($ul.eq($ul.length - 1));
						$newElement.click(function() {
							$("#typemgr-modal .select li").removeClass('selected');
							$(this).addClass("selected");

							$("#typemgr-modal input[name='typename']").val($(this).children('a').text());
						});
						$newElement.click();
						$(".modal-box.active").attr('changed', true);
					});

					$("#typemgr-modal").addClass('active');
					$("#typemgr-modal").css("display", "block");
				}
			});

			$(".modal-button").click(function(n) {
				var modal = $(".modal-box.active").attr('id');
				var name = $(this).text();
				if (modal == "typemgr-modal") {
					$("#typemgr-req").addClass("none");
					var $selitem = $("#typemgr-modal .select ul li.selected");
					if ($selitem.length < 0)
						return;

					var text = $("#typemgr-modal input[name='typename']").val();
					if (text == "") {
						$("#typemgr-req").val("不能为空");
						$("#typemgr-req").removeClass("none");
						return;
					}
					var oldtext = $selitem.children('a').text();
					if (text !== oldtext) {
						if (gettypeindex(text) >= 0) {
							$("#typemgr-req").val("已有该名称的类型");
							$("#typemgr-req").removeClass("none");
							return;
						}

					}
					var typeindex = gettypeindex(oldtext);
					if (name == "保存") {
						if (types[typeindex] !== text) {
							var sortstr = getCookie("sort_type");
							sortstr = sortstr.replace(types[typeindex], text);
							setCookie("sort_type", sortstr);
						}

						$selitem.children('a').html(text);
						types[typeindex] = {
							"name": text,
							"user": true
						};
						$(".modal-box.active").attr('changed', true);
					} else if (name == "删除") {
						if (sites[typeindex].length > 0) {
							alert("请先删除该分组下的站点");
							return;
						}
						types.splice(typeindex, 1);
						sites.splice(typeindex, 1);
						$("#typemgr-modal .select ul li.selected").remove();
						$("#typemgr-modal input[name='typename']").attr("value", "");
						$(".modal-box.active").attr('changed', true);
					}
				}
				if (modal == "addsite-modal") {
					if (name == "删除") {
						var oldtypeindex = parseInt($(".modal").attr("typeindex"));
						var webindex = parseInt($(".modal").attr("siteindex"));
						sites[oldtypeindex].splice(webindex, 1);

						$(".modal-box.active").attr('changed', true);
						$(".modal-close").click();
						return;
					}
					$("#addsite-modal span").addClass("none");
					if ($("#addsite-modal input[name='site-name']").val() == "") {
						$("#site-name-req").removeClass("none");
						return;
					}
					if ($("#addsite-modal input[name='site-url']").val() == "") {
						$("#site-url-req").removeClass("none");
						return;
					}
					if ($("#addsite-modal input[name='site-query']").val() == "") {
						$("#site-query-req").removeClass("none");
						return;
					}
					if ($("#addsite-modal input[name='site-ico']").val() == "") {
						$("#site-ico-req").removeClass("none");
						return;
					}

					var typeindex = $("#addsite-modal .select ul li.selected").attr('typeindex');
					var site = [];
					site[0] = $("#addsite-modal input[name='site-name']").val();
					site[1] = $("#addsite-modal input[name='site-memo']").val();
					site[2] = $("#addsite-modal input[name='site-url']").val();
					site[3] = $("#addsite-modal input[name='site-query']").val();
					site[4] = $("#addsite-modal input[name='site-ico']").val();
					site[5] = false;
					site[6] = true;
					if ($(".modal").attr("modify") == "true") {
						var oldtypeindex = parseInt($(".modal").attr("typeindex"));
						var webindex = parseInt($(".modal").attr("siteindex"));
						site[5] = sites[oldtypeindex][webindex][5];
						if (site[0] !== sites[oldtypeindex][webindex][0]) {
							var sortstr = getCookie("sort_websits_" + oldtypeindex);
							sortstr = sortstr.replace(sites[oldtypeindex][webindex][0], site[0]);
							setCookie("sort_websits_" + oldtypeindex, sortstr);

							var favorite = getCookie("favorite");
							favorite = favorite.replace(sites[oldtypeindex][webindex][0], site[0]);
							setCookie("favorite", favorite);
						}

						if (oldtypeindex == typeindex) {
							sites[typeindex][webindex] = site;
						} else {
							sites[oldtypeindex].splice(webindex, 1);
							sites[typeindex].push(site);
						}
					} else
						sites[typeindex].push(site);
					$(".modal-box.active").attr('changed', true);
					$(".modal-close").click();
				}
				if (modal == "addmultiple-modal") {
					if (name == "删除") {
						var oldtypeindex = parseInt($(".modal").attr("typeindex"));
						var webindex = parseInt($(".modal").attr("siteindex"));
						sites[oldtypeindex].splice(webindex, 1);

						$(".modal-box.active").attr('changed', true);
						$(".modal-close").click();
						return;
					}

					$("#addmultiple-modal span").addClass("none");
					if ($("#addmultiple-modal input[name='multiple-name']").val() == "") {
						$("#multiple-name-req").removeClass("none");
						return;
					}
					var items = [];
					if ($("#addmultiple-modal .fs-label").text() == "请选择站点") {
						$("#multiple-sites-req").removeClass("none");
						return;
					} else {
						items = $("#addmultiple-modal .fs-label").text().split(';');
						if (items.length < 2 || items.length > 4) {
							$("#multiple-sites-req").removeClass("none");
							return;
						}
					}


					var typeindex = $("#addmultiple-modal .select ul li.selected").attr('typeindex');
					var site = [];
					site[0] = $("#addmultiple-modal input[name='multiple-name']").val();
					site[1] = $("#addmultiple-modal input[name='multiple-memo']").val();
					site[2] = "multiple";
					site[3] = $("#addmultiple-modal .fs-label").text();
					site[4] = "template" + items.length;
					site[5] = false;
					site[6] = true;
					if ($(".modal").attr("modify") == "true") {
						var oldtypeindex = parseInt($(".modal").attr("typeindex"));
						var webindex = parseInt($(".modal").attr("siteindex"));
						site[5] = sites[oldtypeindex][webindex][5];
						if (site[0] !== sites[oldtypeindex][webindex][0]) {
							var sortstr = getCookie("sort_websits_" + oldtypeindex);
							sortstr = sortstr.replace(sites[oldtypeindex][webindex][0], site[0]);
							setCookie("sort_websits_" + oldtypeindex, sortstr);

							var favorite = getCookie("favorite");
							favorite = favorite.replace(sites[oldtypeindex][webindex][0], site[0]);
							setCookie("favorite", favorite);
						}

						if (oldtypeindex == typeindex) {
							sites[typeindex][webindex] = site;
						} else {
							sites[oldtypeindex].splice(webindex, 1);
							sites[typeindex].push(site);
						}
					} else
						sites[typeindex].push(site);
					$(".modal-box.active").attr('changed', true);
					$(".modal-close").click();
				}
			});

			$(".modal-close").click(function(n) {
				if ($(".modal-box.active").attr('changed') == "true") {
					bulidtype();
					bulidfavorites();
					var first = $('#cur_subtype li').attr("typeindex");
					selecttabtype(first);
					$(".modal-box.active").attr('changed', false);

					//保存自定义数据
					//分组
					var usertypes = [];
					for (index in types) {
						if (types[index].user == true)
							usertypes.push(types[index]);
					}
					//if(usertypes.length > 0){
					setCookie("usertypes", JSON.stringify(usertypes));
					//}
					//站点		
					for (index in types) {
						var items = sites[index];
						var usersites = [];
						for (i in items) {
							if (items[i][6] == true)
								usersites.push(items[i]);
						}
						//if(usersites.length > 0){
						setCookie("usersites_" + index, JSON.stringify(usersites));
						//}

					}
				}
				$(".modal").attr("modify", false);
				$(".modal").attr("typeindex", "");
				$(".modal").attr("siteindex", "");

				$(".modal").removeClass('active');
				$(".modal").css("display", "none");
				$(".modal-box").removeClass('active');
				$(".modal-box").css("display", "none");

			});

			$(".modal").click(function(n) {
				if ($(n.target).hasClass("modal"))
					$(".modal-close").click();
			});
		</script>
		<!--satrt输入框提示-->
		<script>
			$("#search-input-box input").blur(function() {
				$("#search-keywords").removeClass("active")
			});

			$("#keywords").bind("mouseup", function(event) {
				if ($("#search-keywords ul li")[0])
					$("#search-keywords").addClass('active');
			});
			/*设置监听事件，向输入框中输入内容，当键盘按键弹起的时候，将输入的内容作为参数传入到函数info中*/
			$("#keywords").bind("keyup", function(event) {
				/*当键盘按下上下键的时候，不进行监听，否则会与keyup事件起冲突*/
				if (event.keyCode == 38 || event.keyCode == 40) {
					var index = $("#search-keywords>ul>li.over").index();
					if (index < 0)
						index = 0;
					else {
						if (event.keyCode == 40) {
							index++;
							if (index >= $("#search-keywords ul li").length)
								index = 0;
						} else {
							index--;
							if (index < 0)
								index = $("#search-keywords ul li").length - 1;
						}
					}
					$("#search-keywords ul li").removeClass("over");
					$("#search-keywords ul li").eq(index).addClass("over");

					var text = $("#search-keywords ul li").eq(index).children('a').attr("data-keyword");
					$("#search-input-box input").val(text);

					return false;
				}
				if (event.keyCode == 13) {
					if ($("#search-keywords").hasClass('active')) {
						$("#search-keywords").removeClass("active");
					}
					search();

					return false;
				}

				var value = $("#keywords").val();
				info(value);
			});

			/*将ajax封装到函数中*/
			function info(value) {
				/*百度搜索框智能提示的接口*/
				var url = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su";
				/*需要传入的参数，cb是callback的缩写*/
				var data = {
					wd: value,
					cb: "helloword"
				}
				/*因为涉及跨域，这里使用jsonp*/
				$.ajax({
					url: url,
					data: data,
					type: "GET",
					dataType: "jsonp",
					jsonpCallback: "helloword",
					/*跨域成功的时候返回的数据*/
					success: function(result) {
						/*将获取的数据整理后返回到页面*/
						var a = result.s;
						var list = "";
						for (var i in a) {
							var l = a[i];
							list += '<li><a href="javascript:void(0);" data-keyword="' + l + '">' + l + '</a></li>';
						}
						$("#search-keywords ul").html(list);
						if (list == "")
							$("#search-keywords").removeClass('active');
						else {
							$("#search-keywords").addClass('active');
							$("#search-keywords li a").click(function() {
								$("#search-keywords").removeClass("active");
								$("#search-input-box input").val($(this).attr("data-keyword"));
								//i($(this).attr("data-keyword"))
							});

							$("#search-keywords li").mouseover(function() { //鼠标滑过  
									$(this).addClass("over");
								})
								.mouseout(function() { //鼠标滑出  
									$(this).removeClass("over");
								})
						}



					},
					/*跨域失败的时候返回的数据*/
					error: function() {
						console.log("error");
					}
				})
			}
		</script>
		<!--end输入框提示-->

		<script>
			var node = document.querySelector("#cur_subtype,#websites");
			var draging = null;
			//使用事件委托，将li的事件委托给ul
			node.ondragstart = function(event) {
				//console.log("start");
				//firefox设置了setData后元素才能拖动！！！！
				event.dataTransfer.setData("te", event.target.innerText); //不能使用text，firefox会打开新tab
				//event.dataTransfer.setData("self", event.target);
				draging = event.target;
			}
			node.ondragover = function(event) {
				//console.log("onDrop over");
				event.preventDefault();
				var target = event.target;
				//因为dragover会发生在ul上，所以要判断是不是li

				if (target.nodeName !== "LI")
					target = target.parentNode;
				if (draging.nodeName !== "LI")
					draging = draging.parentNode;

				if (target.parentNode !== draging.parentNode)
					return;
				if (target.nodeName === "LI" && draging.nodeName === "LI" && target !== draging) {
					if (_index(draging) < _index(target)) {
						target.parentNode.insertBefore(draging, target.nextSibling);
					} else {
						target.parentNode.insertBefore(draging, target);
					}
				}
			}
			node.ondragend = function(event) {
				//var drag = event.target;
				if (draging.nodeName !== "LI")
					draging = draging.parentNode;

				var target = draging.parentNode;
				if (target.id === "cur_subtype") {
					var sort = "";
					var $items = $(target.children);
					$items.each(function() {
						sort += ";" + $(this).children("a").text();
					});
					if (sort.length > 0)
						sort = sort.substr(1);
					setCookie("sort_type", sort);
				}
				if (target.id === "websites" || target.id === "faveriters") {
					var sort = "";
					var $items = $(target.children);
					$items.each(function() {
						sort += ";" + $(this).children("span").text();
					});
					if (sort.length > 0)
						sort = sort.substr(1);

					if (target.id === "faveriters") {
						setCookie("favorite", sort);
					} else {
						var typeindex = $('#cur_subtype li.selected').attr("typeindex");
						setCookie("sort_websits_" + typeindex, sort);
					}
				}
			}
			//获取元素在父元素中的index
			function _index(el) {
				var index = 0;

				if (!el || !el.parentNode) {
					return -1;
				}

				while (el && (el = el.previousElementSibling)) {
					//console.log(el);
					index++;
				}

				return index;
			}
			var node1 = document.querySelector("#websites");
			node1.ondragstart = node.ondragstart;
			node1.ondragover = node.ondragover;
			node1.ondragend = node.ondragend;
			var node2 = document.querySelector("#faveriters");
			node2.ondragstart = node.ondragstart;
			node2.ondragover = node.ondragover;
			node2.ondragend = node.ondragend;
		</script>
	</body>
</html>
